1 module geany_dlang.dcd_wrapper;
2 
3 import dcd.server.server;
4 import dsymbol.modulecache;
5 import logger;
6 import dcd.common.messages;
7 import dcd.common.messages: Request = AutocompleteRequest, Response = AutocompleteResponse;
8 
9 class DcdWrapper
10 {
11     package ModuleCache cache;
12 
13     this()
14     {
15         cache = ModuleCache(new ASTAllocator);
16     }
17 
18     static string[] loadConfiguredImportDirs() @trusted
19     {
20         return dcd.server.server.loadConfiguredImportDirs();
21     }
22 
23     void addImportPaths(string[] pathLines)
24     {
25         cache.addImportPaths(pathLines);
26     }
27 
28     void removeImportPaths(in string[] pathLines)
29     {
30         cache.removeImportPaths(pathLines);
31     }
32 
33     string listImportPaths()
34     {
35         auto g = cache.getImportPaths();
36         string ret;
37 
38         foreach(s; g)
39             ret ~= s~"\n";
40 
41         return ret;
42     }
43 
44     void clearCache()
45     {
46         info("Clearing cache.");
47         cache.clear();
48     }
49 
50     Response doRequest(Request request) nothrow
51     {
52         import dcd.server.autocomplete;
53         import std.conv: to;
54         import std.exception;
55 
56         nothrowLog!"info"("Do request. kind = "~request.kind.to!string);
57 
58         Response ret;
59 
60         try
61         {
62             with(RequestKind)
63             switch(request.kind)
64             {
65                 case autocomplete:
66                     ret = complete(request, cache);
67                     break;
68 
69                 case doc:
70                     try
71                         ret = getDoc(request, cache);
72                     catch (Exception e)
73                         nothrowLog!"warning"("Could not get DDoc information: "~e.msg);
74 
75                     break;
76 
77                 case symbolLocation:
78                     try
79                         ret = findDeclaration(request, cache);
80                     catch (Exception e)
81                         nothrowLog!"warning"("Could not get symbol location: "~e.msg);
82 
83                     break;
84 
85                 case search:
86                     ret = symbolSearch(request, cache);
87                     break;
88 
89                 case localUse:
90                     try
91                         ret = findLocalUse(request, cache);
92                     catch (Exception e)
93                         nothrowLog!"warning"("Could not find local usage: "~e.msg);
94 
95                     break;
96 
97                 default:
98                     throw new Exception("Unsupported request kind");
99             }
100         }
101         catch(Exception e)
102         {
103             nothrowLog!"warning"(e.msg);
104         }
105 
106         return ret;
107     }
108 }